package main

import (
	"VoteProgram/controller"
	"VoteProgram/dao"
	"github.com/gin-gonic/gin"
	_ "github.com/jinzhu/gorm/dialects/mysql"
	"VoteProgram/models"
)


func main() {
	//初始化数据库
	err := dao.InitMysql()
	if err != nil{
		panic(err)
	}
	defer dao.DB.Close()//程序退出关闭连接
	models.InitThumbData()

	//模型绑定
	dao.DB.AutoMigrate(&models.Students{},&models.Visitors{},&models.ThumbsIp{})
	r := gin.Default()
	//加载静态文件
	r.Static("./static","static")
	//加载模板
	r.LoadHTMLGlob("templates/*")
	//路由
	r.GET("/index",controller.HomePage)
	r.GET("/sign-up",controller.Sign_up)
	r.GET("/act-intro",controller.Act_intro)
	r.POST("/sign-up",controller.Sign_up_post)
	r.GET("/id=:id/detail",controller.Give_thumb)
	r.Run("127.0.0.1:8080")
}
